package com.yequan.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @author : Administrator
 * @date : 2020/3/23
 */
public class MyScheduler {

    public static void main(String[] args) throws SchedulerException, InterruptedException {
        //1. 创建调度器
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = stdSchedulerFactory.getScheduler();
        //2. 创建任务
        JobDetail jobDetail = JobBuilder.newJob(PrintWordsJob.class)
                .withIdentity("job1", "group1")
                .usingJobData("JobDetail-Key1", "JobDetail-1")
                .build();
        //3. 创建触发器
        SimpleTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "triggerGroup1")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(60).repeatForever())
                .usingJobData("Trigger-key1", "Trigger-1")
                .build();
        //4. 执行
        scheduler.scheduleJob(jobDetail, trigger);
        System.out.println("-----start----");
        scheduler.start();


        TimeUnit.MINUTES.sleep(1);
//        scheduler.shutdown();
        System.out.println("-----end----");
    }

}
